package com.admin.business.voteOwnerMeeting;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 召开业主大会记录
 * @create: 2022-07-08 19:04:49
 **/
@Service("voteOwnerMeeting")
@Slf4j
public class VoteOwnerMeetingService{

    @Resource
    VoteOwnerMeetingDao voteOwnerMeetingDao;

    /**
     * 添加召开业主大会记录,获取id数据
     *
     * @param cdoRequest - id:
     *                   - user_id:用户id
     *                   - essential_information_id:基本信息id
     *                   - preparation_vote_user_id:筹备组组长id
     *                   - proprietor_statute:业主规约
     *                   - deliberation_rule:议事规则
     *                   - owner_meeting_programme:召开业主大会方案
     *                   - candidate_committe:认证候选委员方案
     *                   - publicity_picture:上传线下公示图片
     *                   - meeting_time:召开时间
     *                   - expand_time:延长时间
     *                   - committee_number:委员人数
     *                   - replenish_number:后补委员人数
     *                   - director_number:主任人数
     *                   - deputy_director_number:副主任人数
     *                   - update_time:更新时间
     *                   - begin_time:创建时间
     *                   - state:删除，0正常1删除
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return addVoteOwnerMeeting(CDO cdoRequest) {
        voteOwnerMeetingDao.addVoteOwnerMeeting(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新召开业主大会记录数据
     *
     * @param cdoRequest - id:
     *                   - user_id:用户id
     *                   - essential_information_id:基本信息id
     *                   - preparation_vote_user_id:筹备组组长id
     *                   - proprietor_statute:业主规约
     *                   - deliberation_rule:议事规则
     *                   - owner_meeting_programme:召开业主大会方案
     *                   - candidate_committe:认证候选委员方案
     *                   - publicity_picture:上传线下公示图片
     *                   - meeting_time:召开时间
     *                   - expand_time:延长时间
     *                   - committee_number:委员人数
     *                   - replenish_number:后补委员人数
     *                   - director_number:主任人数
     *                   - deputy_director_number:副主任人数
     *                   - update_time:更新时间
     *                   - begin_time:创建时间
     *                   - state:删除，0正常1删除
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return updateVoteOwnerMeetingById(CDO cdoRequest) {
        int affectedRows = voteOwnerMeetingDao.updateVoteOwnerMeetingById(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，删除召开业主大会记录数据
     *
     * @param cdoRequest - id:
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return deleteVoteOwnerMeetingById(CDO cdoRequest){
        int affectedRows = voteOwnerMeetingDao.deleteVoteOwnerMeetingById(cdoRequest.getInteger("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除召开业主大会记录数据
     *
     * @param cdoRequest
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return deleteVoteOwnerMeeting(CDO cdoRequest) {
        int affectedRows = voteOwnerMeetingDao.deleteVoteOwnerMeeting(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取召开业主大会记录数据
     *
     * @param cdoRequest - id:
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return getVoteOwnerMeetingById(CDO cdoRequest) {
        CDO cdoMapperResult = voteOwnerMeetingDao.getVoteOwnerMeetingById(cdoRequest.getInteger("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据混合条件，获取召开业主大会记录数据
     *
     * @param cdoRequest - id:
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return getVoteOwnerMeeting(CDO cdoRequest) {
        CDO cdoMapperResult = voteOwnerMeetingDao.getVoteOwnerMeeting(cdoRequest);
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取召开业主大会记录数据列表
     *
     * @param cdoRequest
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return getVoteOwnerMeetingList(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = voteOwnerMeetingDao.getVoteOwnerMeetingList(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = voteOwnerMeetingDao.getVoteOwnerMeetingListCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据混合条件，获取召开业主大会记录数据列表
     *
     * @param cdoRequest - id:
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return getVoteOwnerMeetingListByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = voteOwnerMeetingDao.getVoteOwnerMeetingListByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = voteOwnerMeetingDao.getVoteOwnerMeetingListByConditionCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
